import numpy
import matplotlib.pyplot as plt
from scipy import signal
from scipy.io import wavfile
import sys
import spectrogram as tk
from util import default_params
if len(sys.argv)<2:
   sys.exit(1)



wav_file_name = sys.argv[1]
if not wav_file_name.startswith("/"): 
    wav_file_name = "k:/matlab/speech/speech_commands_v0.01/" + wav_file_name




if not wav_file_name.endswith(".wav"): 
   wav_file_name+=".wav"
   
print(wav_file_name)
inst = tk.spectrogram()
params=default_params()
inst.set_param(**params)
sample_rate, samples = wavfile.read(wav_file_name)
nrow = samples.shape[0]
inst.setup(sample_rate,nrow)

spectrogram = inst.calc(samples)

plt.pcolormesh(  spectrogram)
#plt.imshow(spectrogram)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.grid()
plt.show()

#print(sample_rate)
#print(samples)
#print(frequencies)
#print( times)
